package com.glb.leetcode;

import java.util.Arrays;
import java.util.Scanner;

public class HB_test2 {

	public static void main(String[] args) {
		int reacCapacity = 100;
		int criticalMass = 15;
		int[] vol = {50, 40, 30, 20, 10};
		int[] mass = {1, 2, 3, 9, 5};
		int[] energy = {300, 480, 270, 200, 180};
		
		int result = maxEnergyGenerate(reacCapacity, criticalMass, vol, mass, energy);
		System.out.println("最大能量是: " + result);  // 输出960
		
		int reacCapacity2 = 250;
		int criticalMass2 = 25;
		int[] vol2 = {30, 40, 50, 60, 70};
		int[] mass2 = {7, 8, 9, 10, 11};
		int[] energy2 = {300, 400, 500, 600, 700};
		
		int result2 = maxEnergyGenerate(reacCapacity2, criticalMass2, vol2, mass2, energy2);
		System.out.println("最大能量是: " + result2);  // 输出1300
}

public static int  maxEnergyGenerate2(int reacCapacity, int criticalMass, int[] vol, int[] mass, int[] energy){
	int  answer = 0;

	int length = Math.min(Math.min(vol.length, mass.length), energy.length);

	int[][] energies = new int[length][length];
	for (int i = 0; i < length; i++) {
		energies[vol[i]][mass[i]] = energy[i];
	}
	System.out.println(Arrays.deepToString(energies));

	return answer;
}

/**
 * 
 * @param reacCapacity
 * @param criticalMass
 * @param vol, 容器数组
 * @param mass, 质量
 * @param energy, 能量
 * @return
 */
  public static int  maxEnergyGenerate(int reacCapacity, int criticalMass, int[] vol, int[] mass, int[] energy)
	{
		int  answer = 0;
		// Write your code here
		int n = vol.length;
		int[][][] dp = new int[n + 1][reacCapacity + 1][criticalMass + 1];
		
		for (int i = 1; i <= n; i++) {
				for (int v = 0; v <= reacCapacity; v++) {
						for (int m = 0; m <= criticalMass; m++) {
								dp[i][v][m] = dp[i - 1][v][m];
								if (v >= vol[i - 1] && m >= mass[i - 1]) {
										dp[i][v][m] = Math.max(dp[i][v][m], dp[i - 1][v - vol[i - 1]][m - mass[i - 1]] + energy[i - 1]);
								}
						}
				}
		}

		answer =  dp[n][reacCapacity][criticalMass];
		
		return answer;
	}

}
